function  New_Counter_Tables(data_baseline, data_no_inequality, data_no_between_inequality, data_no_within_inequality, data_truncated_10th , data_halved_cost_inv , fp)

%cd(fp.paper)    

%Collecting data together for skills at end of high-school;

data{1} = [];
data{2} = [];
data{3} = [];
data{4} = [];
data{5} = [];
data{6} = [];

%data_reduced_invcost = [];
%data_reduced_invcost_baseline = [];

data_other{1} = [];
data_other{2} = [];
data_other{3} = [];
data_other{4} = [];
data_other{5} = [];
data_other{6} = [];

for h = 1 : fp.n_rip_sim


for j = 1:4
    
    data{1} = [data{1} ; [data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )  ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )) ).*j ] ];
    data{2} = [data{2} ; [data_no_inequality{j}(  data_no_inequality{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h  ))).*j ] ];
    data{3} = [data{3} ; [data_no_between_inequality{j}(  data_no_between_inequality{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h ))).*j ] ];
    data{4} = [data{4} ; [data_no_within_inequality{j}(  data_no_within_inequality{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h ))).*j ] ];
    data{5} = [data{5} ; [data_truncated_10th{j}(  data_truncated_10th{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h ))).*j ] ];
    data{6} = [data{6} ; [data_halved_cost_inv{j}(  data_halved_cost_inv{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==11, fp.ind_data.child_C_tp1 ,h ))).*j ] ];

%    data_reduced_invcost_baseline = [data_reduced_invcost_baseline        ; [  repmat(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)==9, fp.ind_data.child_C ,h ) , [2,1])  data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age ,h )<11, fp.ind_data.ParStyle ,h )      ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, fp.ind_data.ParStyle  ,h))).*j ] ];            
%    data_reduced_invcost          = [data_reduced_invcost                 ; [  repmat(data_reduced_inv_cost{j}(  data_reduced_inv_cost{j}(:,fp.ind_data.child_age,h)==9, fp.ind_data.child_C ,h ) , [2,1]) data_reduced_inv_cost{j}(  data_reduced_inv_cost{j}(:,fp.ind_data.child_age ,h)<11,  fp.ind_data.ParStyle  ,h )      ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, fp.ind_data.ParStyle ,h ))).*j ] ];            

    data_other{1} = [data_other{1} ; [data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age ,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h )  ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h ) , 1 ) , 1).*j ] ];
    data_other{2} = [data_other{2} ; [data_no_inequality{j}(  data_no_inequality{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h ) , 1 ) , 1).*j ] ];
    data_other{3} = [data_other{3} ; [data_no_between_inequality{j}(  data_no_between_inequality{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h )              ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h ) , 1 ) , 1).*j ] ];
    data_other{4} = [data_other{4} ; [data_no_within_inequality{j}(  data_no_within_inequality{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h )      ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h ) , 1 ) , 1).*j ] ];        
    data_other{5} = [data_other{5} ; [data_truncated_10th{j}(  data_truncated_10th{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h )      ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h ) , 1 ) , 1).*j ] ];        
    data_other{6} = [data_other{6} ; [data_halved_cost_inv{j}(  data_halved_cost_inv{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h )      ones(size(data_baseline{j}(  data_baseline{j}(:,fp.ind_data.child_age,h)<11, [fp.ind_data.ParStyle fp.ind_data.inv ] ,h ) , 1 ) , 1).*j ] ];        

end
end

    %%%%%%%%%%%%%%%%%%%%;
    % Table;
    %%%%%%%%%%%%%%%%%%%%;
    
    label_param=cell(2,1);
    label_param{1}=uint16('Baseline');
	label_param{2}=uint16('No Inequality'); 
    label_param{3}=uint16('No Between-Neighb. Inequality'); 
    label_param{4}=uint16('No Within-Neighb. Inequality'); 
    label_param{5}=uint16('Truncate Local Distrib. at 10th percent'); 
    label_param{6}=uint16('Halving Cost of Parental Investments'); 
    
    
%%%%%%%%%%%%%%%;    
%Table;    
%%%%%%%%%%%%%%%;


    FID = fopen('Table_New_Counters_Policy_new.tex', 'w');
    fprintf(FID, '\\begin{tabular}{lcccccc}\\hline \\hline \n');
    fprintf(FID, '   &  (1) & (2) & (3) & (4) & (5) & (6)   \\\\ \n ');
    fprintf(FID, ' & \\multicolumn{6}{c}{Panel A: Aggregate}  \\\\ \\cline{2-7}   \n');
    fprintf(FID, '   &  Mean &   90--10 Ratio & 10th Percentile & Gini & Author Parenting & Time Inv  \\\\ \\hline  \n ');    
    for i = 2:6
        ind_label = i;
        
       skills_90 = prctile(  data{i}(:,1)  , 90 );
       skills_90_baseline = prctile(  data{1}(:,1)  , 90 );
       
       skills_10 = prctile(  data{i}(:,1)  , 10 );        
       skills_10_baseline = prctile(  data{1}(:,1)  , 10 );                
       
       inequality = skills_90/skills_10;
       inequality_baseline = skills_90_baseline/skills_10_baseline;  
       cd(fp.matlab)
       g_baseline =gini(ones(size(data{1}(:,1))) , data{1}(:,1) );
       g          =gini(ones(size(data{i}(:,1))) , data{i}(:,1) );
%       cd(fp.paper)
       change_inequality = 100*(inequality-inequality_baseline)/inequality_baseline;

       change_10 = 100*(skills_10-skills_10_baseline)/skills_10_baseline;
%       change_gini = 100*(g - g_baseline)/g_baseline;
       change_gini =  g - g_baseline ;
       
       ps_baseline = nanmean( data_other{1}(:,1) ) ;
       ps          = nanmean( data_other{i}(:,1) ) ;
       
       change_ps = ps - ps_baseline;
       
       inv_baseline = nanmean( data_other{1}(:,2) ) ;
       inv          = nanmean( data_other{i}(:,2) ) ;
       
       change_inv = inv - inv_baseline;          
       
       
%        fprintf(FID, '%s & %3.2f\\%%   & %3.2f\\%% & %3.2f\\%% & %3.2f & %s & %3.2f\\%%   & %3.2f\\%% & %3.2f\\%% & %3.2f & %s & %3.2f\\%%  & %3.2f\\%% & %3.2f\\%% & %3.2f \\\\[0.5cm] \n', ...
%        char(label_param{ind_label}),  100*(nanmean(data{i}(:,1)) - nanmean(data{1}(:,1)))/nanmean(data{1}(:,1)) ,  change_inequality , change_10 , change_gini, '' ,  100*(nanmean(data{i}( data{i}(:,2)==1 ,1)) - nanmean(data{1}( data{1}(:,2)==1 ,1)))/nanmean(data{1}( data{1}(:,2)==1 ,1)) ,  change_inequality_n1 ,change_10_n1, change_gini_n1 , '' , 100*(nanmean(data{i}( data{i}(:,2)==4 ,1)) - nanmean(data{1}( data{1}(:,2)==4 ,1)))/nanmean(data{1}( data{1}(:,2)==4 ,1)) ,  change_inequality_n4 , change_10_n4 , change_gini_n4); 
        fprintf(FID, '%s & %3.2f\\%%   & %3.2f\\%% & %3.2f\\%% & %3.2f & %3.2f & %3.2f  \\\\ \n', ...
        char(label_param{ind_label}),  100*(nanmean(data{i}(:,1)) - nanmean(data{1}(:,1)))/nanmean(data{1}(:,1)) ,  change_inequality , change_10 , change_gini, change_ps , change_inv ); 
        
   
    end     

   
        
    fprintf(FID, ' & \\multicolumn{6}{c}{Panel B: Low-Income Neighborhood}  \\\\ \\cline{2-7}   \n');
    fprintf(FID, '   &  Mean &   90--10 Ratio & 10th Percentile & Gini & Author Parenting & Time Inv  \\\\ \\hline  \n ');     
    
    
    for i = 2:6
           ind_label = i;

       skills_90 = prctile( data{i}(data{i}(:,2)==1 ,1) , 90 );
       skills_90_baseline = prctile( data{1}(data{1}(:,2)==1,1) , 90 );
       
       skills_10 = prctile(  data{i}(data{i}(:,2)==1,1) , 10 );        
       skills_10_baseline = prctile(  data{1}(data{1}(:,2)==1,1) , 10 );                
       
       inequality = skills_90/skills_10;
       inequality_baseline = skills_90_baseline/skills_10_baseline;  
       
       change_inequality_n1 = 100*(inequality-inequality_baseline)/inequality_baseline;
       change_10_n1 = 100*(skills_10-skills_10_baseline)/skills_10_baseline;       
       cd(fp.matlab)
       g_baseline =gini(ones(size(data{1}(data{1}(:,2)==1,1))) , data{1}(data{1}(:,2)==1,1) );
       g          =gini(ones(size(data{i}(data{i}(:,2)==1,1))) , data{i}(data{i}(:,2)==1,1) );       
%       cd(fp.paper)
       change_gini_n1 = g - g_baseline ;
  
       ps_baseline = nanmean( data_other{1}(data_other{1}(:,3)==1,1) ) ;
       ps          = nanmean( data_other{i}(data_other{i}(:,3)==1,1) ) ;
       
       change_ps_n1 = ps - ps_baseline;
       
       inv_baseline = nanmean( data_other{1}(data_other{1}(:,3)==1,2) ) ;
       inv          = nanmean( data_other{i}(data_other{i}(:,3)==1,2) ) ;
       
       change_inv_n1 = inv - inv_baseline;        
       
       
    
        fprintf(FID, '%s & %3.2f\\%%   & %3.2f\\%% & %3.2f\\%% & %3.2f & %3.2f & %3.2f  \\\\ \n', ...
        char(label_param{ind_label}),  100*(nanmean(data{i}(data{i}(:,2)==1,1)) - nanmean(data{1}(data{1}(:,2)==1,1)))/nanmean(data{1}(data{1}(:,2)==1,1)) ,  change_inequality_n1 , change_10_n1 , change_gini_n1, change_ps_n1 , change_inv_n1  ); 
               
       
    end    
    
     
    fprintf(FID, ' & \\multicolumn{6}{c}{Panel C: High-Income Neighborhood}  \\\\ \\cline{2-7}   \n');
    fprintf(FID, '   &  Mean &   90--10 Ratio & 10th Percentile & Gini & Author Parenting & Time Inv  \\\\ \\hline  \n ');     
          
    
    for i = 2:6
        ind_label = i;

 
       skills_90 = prctile( data{i}(data{i}(:,2)==4 ,1) , 90 );
       skills_90_baseline = prctile( data{1}(data{1}(:,2)==4,1) , 90 );
       
       skills_10 = prctile( data{i}(data{i}(:,2)==4,1) , 10 );        
       skills_10_baseline = prctile( data{1}(data{1}(:,2)==4,1) , 10 );                
       
       inequality = skills_90/skills_10;
       inequality_baseline = skills_90_baseline/skills_10_baseline;  
       
       change_inequality_n4 = 100*(inequality-inequality_baseline)/inequality_baseline;
       change_10_n4 = 100*(skills_10-skills_10_baseline)/skills_10_baseline;       
       
       cd(fp.matlab)
       g_baseline =gini(ones(size(data{1}(data{1}(:,2)==4,1))) , data{1}(data{1}(:,2)==4,1) );
       g          =gini(ones(size(data{i}(data{i}(:,2)==4,1))) , data{i}(data{i}(:,2)==4,1) );       
%       cd(fp.paper)
       change_gini_n4 = g - g_baseline ;
  
       ps_baseline = nanmean( data_other{1}(data_other{1}(:,3)==4,1) ) ;
       ps          = nanmean( data_other{i}(data_other{i}(:,3)==4,1) ) ;
       
       change_ps_n4 = ps - ps_baseline;
       
       inv_baseline = nanmean( data_other{1}(data_other{1}(:,3)==4,2) ) ;
       inv          = nanmean( data_other{i}(data_other{i}(:,3)==4,2) ) ;
       
       change_inv_n4 = inv - inv_baseline;        
       
       
    
        fprintf(FID, '%s & %3.2f\\%%   & %3.2f\\%% & %3.2f\\%% & %3.2f & %3.2f & %3.2f  \\\\ \n', ...
        char(label_param{ind_label}),  100*(nanmean(data{i}(data{i}(:,2)==4,1)) - nanmean(data{1}(data{1}(:,2)==4,1)))/nanmean(data{1}(data{1}(:,2)==4,1)) ,  change_inequality_n4 , change_10_n4 , change_gini_n4, change_ps_n4 , change_inv_n4  ); 
               
       
    end        
    
    
    fprintf(FID, '  \\hline \\hline \n');
    fprintf(FID, '\\end{tabular}\n');
    fclose(FID);     
 
  
    
cd(fp.matlab)
end